<template>
  <div id="diagnosTempDiv">
    <Breadcrumb content="诊断模板" />
    <div class="bodyContent">
      <Splitpanes>
        <Pane size="16">
          <!-- 字典分类  -->
          <vxe-toolbar perfect>
            <template #buttons>
              <div class="smallToolTitle">诊断分类</div>
              <vxe-button type="text" class="button-blue" icon="vxe-icon-refresh" content="刷新" :loading="treeloading" @click="findDiagnosTypeList"></vxe-button>
              <vxe-button type="text" class="button-blue" icon="vxe-icon-square-plus" content="新建根分类" @click="addRootDiagnosTypeDialog()"></vxe-button>
            </template>
          </vxe-toolbar>

          <el-scrollbar style="height: calc(100% - 40px)">
            <div class="sampleType">
              <el-scrollbar>
                <el-tree :expand-on-click-node="false" :default-expand-all="true" :data="diagnosTypeList" :props="defaultProps" node-key="id" ref="dataTreeRef" highlight-current class="tools-tree" @node-click="handleClickType" v-loading="treeloading">
                  <template #default="{ data, node }">
                    <span>{{ data.name }}</span>
                    <div>
                      <span>
                        <!-- 新增  -->
                        <el-button type="success" class="cirBtn" size="small" icon="Plus" circle @click="appendDiagnosType(data)"></el-button>
                        <!-- 编辑  -->
                        <el-button type="warning" class="cirBtn" size="small" icon="Edit" circle @click="editDiagnosType(data, node)"></el-button>
                        <!-- 删除  -->
                        <el-button type="info" class="cirBtn" size="small" icon="Delete" circle @click="deletDiagnosType(data)"></el-button>
                      </span>
                    </div>
                  </template>
                </el-tree>
              </el-scrollbar>
            </div>
          </el-scrollbar>

          <!-- 新建/编辑字典分类弹框 -->
          <el-dialog :title="titleDiagnosType()" :show-close="false" v-model="showTypeDialog" append-to-body :close-on-click-modal="false" width="500px">
            <el-form ref="diagnosTypeFormRef" :model="diagnosTypeForm" :rules="diagnosTypeFormRule" label-width="100px" class="form-input-m" inline-message>
              <el-form-item prop="pname" label="父级分类" v-if="pnameShow">
                <el-input type="text" v-model="diagnosTypeForm.pname" placeholder="请输入父类名称" disabled></el-input>
              </el-form-item>
              <el-form-item prop="code" label="编号">
                <el-input type="text" v-model="diagnosTypeForm.code" placeholder="请输入字典编号" clearable></el-input>
              </el-form-item>
              <el-form-item prop="name" label="名称">
                <el-input type="text" v-model="diagnosTypeForm.name" placeholder="请输入字典名称" clearable></el-input>
              </el-form-item>
              <el-form-item prop="seq" label="排序" class="input-s">
                <el-input-number v-model="diagnosTypeForm.seq" :min="0" :max="100" label="请输入顺序号"></el-input-number>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer flex right justify-end">
              <el-button type="primary" @click="saveDiagnosType('diagnosTypeFormRef')">保存</el-button>
              <el-button @click="closeTypeDialog('diagnosTypeFormRef')">取消</el-button>
            </div>
          </el-dialog>
        </Pane>
        <!-- 左侧表格  -->
        <Pane size="30">
          <vxe-toolbar perfect>
            <template #buttons>
              <!-- <div class="smallToolTitle">供应商维护</div> -->
              <vxe-input style="width: 180px" v-model="searchForm.searchValue" type="search" clearable class="vxeInputSearch" placeholder="关键字查询" @clear="findDiagnosTempList" @keyup="keyupEnter" @search-click="findDiagnosTempList()"></vxe-input>
              <vxe-button type="text" class="button-blue" icon="vxe-icon-refresh" content="刷新" :loading="tloading" @click="findDiagnosTempList"></vxe-button>
              <vxe-button type="text" class="button-blue" icon="vxe-icon-square-plus" content="新建" @click="addDiagnosTempDialog()"></vxe-button>
              <vxe-button type="text" icon="vxe-icon-delete" class="button-red" content="删除" @click="deleteBatchDiagnosTemp"></vxe-button>
            </template>
          </vxe-toolbar>
          <div class="tableBody">
            <vxe-table ref="tempTableRef" class="mytable-scrollbar" border="inner" align="center" height="auto" :data="diagnosTempList" :loading="tloading" @current-change="diagnosTempRowClick" :row-config="{ isCurrent: true, isHover: true }" :column-config="{ resizable: true }" resizable show-overflow keep-source>
              <vxe-column type="checkbox" width="30"></vxe-column>
              <vxe-column field="tempCode" title="诊断编号" width="150">
                <template #default="{ row }">
                  <span>{{ row.tempCode }}</span>
                </template>
              </vxe-column>
              <vxe-column field="tempName" title="诊断名称">
                <template #default="{ row }">
                  <el-link type="primary" :underline="false" @click="editDiagnosTempDialog(row)">
                    <span>{{ row.tempName }}</span>
                  </el-link>
                </template>
              </vxe-column>
              <vxe-column field="isEnable" title="是否启用" width="100">
                <template #default="{ row }">
                  <el-tag :type="row.isEnable===1 ? 'success' : 'danger'">{{ row.isEnable===1 ? '是' : '否' }}</el-tag>
                </template>
              </vxe-column>

              <vxe-column field="seq" title="顺序" width="80">
                <template #default="{ row }">
                  <span>{{ row.seq }}</span>
                </template>
              </vxe-column>
            </vxe-table>
          </div>

          <el-dialog :title="titleDiagnosTemp()" :show-close="false" v-model="showDiagnosTempDialog" append-to-body width="500px" :close-on-click-modal="false">
            <el-form ref="diagnosTempFormRef" :model="diagnosTempForm" :rules="diagnosTempFormRule" label-width="100px" class="form-input-m" inline-message>
              <el-row>
                <el-col :span="24">
                  <el-form-item prop="tempCode" label="诊断编号">
                    <el-input type="text" v-model="diagnosTempForm.tempCode" placeholder="请输入诊断编号" clearable></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item prop="tempName" label="诊断名称">
                    <el-input type="text" v-model="diagnosTempForm.tempName" placeholder="请输入诊断名称" clearable></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item prop="isEnable" label="是否启用">
                    <vxe-switch v-model="diagnosTempForm.isEnable" size="mini" open-label="是" close-label="否" :open-value="1" :close-value="0"></vxe-switch>
                  </el-form-item>
                </el-col>

                <el-col :span="24">
                  <el-form-item prop="order" label="排序">
                    <el-input-number v-model="diagnosTempForm.seq" :min="1" :max="1000" />
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>

            <div class="dialog-footer flex right justify-end">
              <el-button type="primary" @click="saveDiagnosTemp('diagnosTempFormRef')">保存</el-button>
              <el-button @click="closeDiagnosTempDialog('diagnosTempFormRef')">取消</el-button>
            </div>
          </el-dialog>
        </Pane>
        <!-- 右侧表单 -->
        <Pane size="55">
          <el-tabs type="border-card" v-model="activeName">
            <el-tab-pane label="诊断描述" name="first">
              <vxe-toolbar perfect>
                <template #buttons>
                  <vxe-button type="text" class="button-blue" icon="vxe-icon-square-plus" content="新建" @click="addDiagnosTempDescDialog()" :disabled="isEmpty(sltDiagnosTemp.id)"></vxe-button>
                  <vxe-button type="text" icon="vxe-icon-delete" class="button-red" content="删除" @click="deleteBatchDiagnosTempDesc"></vxe-button>
                </template>
              </vxe-toolbar>

              <div class="tableBody">
                <vxe-table ref="diagnosTempDescTableRef" class="mytable-scrollbar" border="inner" align="center" height="auto" :data="diagnosTempDescList" :loading="ploading" :row-config="{ isCurrent: true, isHover: true }" :column-config="{ resizable: true }" resizable show-overflow keep-source>
                  <vxe-column type="checkbox" width="30"></vxe-column>
                  <vxe-column field="descText" title="描述内容">
                    <template #default="{ row }">
                      <el-link type="primary" :underline="false" @click="editDiagnosTempDescDialog(row)">
                        <span>{{ row.descText }}</span>
                      </el-link>
                    </template>
                  </vxe-column>

                  <vxe-column field="isEnable" title="是否启用" width="100">
                    <template #default="{ row }">
                      <el-tag :type="row.isEnable===1 ? 'success' : 'danger'">{{ row.isEnable===1 ? '是' : '否' }}</el-tag>
                    </template>

                  </vxe-column>
                  <vxe-column field="seq" title="顺序" width="50">
                    <template #default="{ row }">
                      <span>{{ row.seq }}</span>
                    </template>
                  </vxe-column>
                </vxe-table>
              </div>

              <el-dialog :title="titleDiagnosTempDesc()" :show-close="false" v-model="showDiagnosTempDescDialog" append-to-body width="500px" :close-on-click-modal="false">
                <el-form ref="diagnosTempDescFormRef" :model="diagnosTempDescForm" :rules="diagnosTempDescFormRule" label-width="80px" class="form-input-m" inline-message>
                  <el-row>
                    <el-col :span="24">
                      <el-form-item prop="descText" label="描述内容">
                        <el-input type="textarea" v-model="diagnosTempDescForm.descText" placeholder="请输入描述内容" style="width: 560px" :rows="7"></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <el-form-item prop="isEnable" label="是否启用">
                        <vxe-switch v-model="diagnosTempDescForm.isEnable" size="mini" open-label="是" close-label="否" :open-value="1" :close-value="0"></vxe-switch>
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <el-form-item prop="order" label="排序">
                        <el-input-number v-model="diagnosTempDescForm.seq" :min="1" :max="1000" />
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form>

                <div class="dialog-footer flex right justify-end">
                  <el-button type="primary" @click="saveDiagnosTempDesc('diagnosTempDescFormRef')">保存</el-button>
                  <el-button @click="closeDiagnosTempDescDialog('diagnosTempDescFormRef')">取消</el-button>
                </div>
              </el-dialog>
            </el-tab-pane>
          </el-tabs>
        </Pane>
      </Splitpanes>
    </div>
  </div>
</template>
<script setup lang="ts">
// 引入组件区 ==========
import { ref, reactive, getCurrentInstance, onMounted } from 'vue';
import Breadcrumb from '@/components/Breadcrumb.vue';
import { Splitpanes, Pane } from 'splitpanes';
let { proxy }: any = getCurrentInstance();
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage'; //提示框
import { isEmpty } from 'lodash';
import { AppStore } from '@/stores/store'; //'../../../stores/store';
let store = AppStore();
// 最左侧的树
let defaultProps = {
  children: 'children',
  label: 'name'
};
// 全局变量定义区 ==========
// 根据质控规则的关键字查询
let searchForm = {
  searchValue: ''
};
let showDiagnosTempDialog = ref(false); //中间字段弹框
let showDiagnosTempDescDialog = ref(false);
let tloading = ref(false); //加载状态
let ploading = ref(false); //加载状态
let diagnosTempDescList: any = reactive([]);
let diagnosTempList: any = reactive([]);
let sltDiagnosTemp: any = ref({});
let activeName = ref('first');

let typeList = [
  { code: 'radio', name: '单选' },
  { code: 'check', name: '多选' },
  { code: 'num', name: '数字' },
  { code: 'txt', name: '文本' }
];

// 最左侧 新建/编辑字典分类弹框表单
let diagnosTypeForm = reactive({
  id: null,
  pid: null,
  code: '',
  name: '',
  pname: '',
  seq: 1
});

// 最左侧字典分类弹框表单校验
let diagnosTypeFormRule = {
  name: [
    {
      required: true,
      message: '请输入字典名称',
      trigger: 'blur'
    },
    {
      min: 2,
      max: 20,
      message: '长度为2到20个字符',
      trigger: 'blur'
    }
  ]
};

// 右侧基本信息表单
let diagnosTempForm = reactive({
  id: null,
  diagnosTypeId: null,
  tempCode: '',
  tempName: '',
  isEnable: 1,
  seq: 1
});

let diagnosTempFormRule = {
  tempName: [
    {
      required: true,
      message: '请输入标准名称',
      trigger: 'blur'
    },
    {
      min: 2,
      max: 20,
      message: '长度为2到20个字符',
      trigger: 'blur'
    }
  ]
};

let diagnosTempDescForm = reactive({
  id: null,
  diagnosTempId: '',
  descCode: '',
  descName: '',
  descText: '',
  isEnable: 1,
  seq: 1
});

let diagnosTempDescFormRule = {
  descText: [
    {
      required: true,
      message: '请输入项目名称',
      trigger: 'blur'
    }
  ]
};

// 方法定义区 =============
// 页面加载时更新列表(左侧)
onMounted(() => {
  findDiagnosTypeList();
});
let treeloading = ref(false); //字典分类树上的刷新
let diagnosTypeList: any = reactive([]); //最左侧字典分类列表数据
let sltType: any = {};

// 获取字典分类列表(树) 刷新
function findDiagnosTypeList() {
  treeloading.value = true;
  diagnosTypeList.length = 0; //放入数据前清空数据
  const url = '/lab/diagnosType/findDiagnosTypeTree';
  proxy.$http
    //注意此处的数据条数
    .get(url, { params: {} })
    .then((res: any) => {
      diagnosTypeList.push(...res.data);
      if (diagnosTypeList.length > 0) {
        const sltObj = getChildren(diagnosTypeList[0]);
        sltType = sltObj;
        setCurTypeNode(sltObj.id);
        findDiagnosTempList();
      }
      treeloading.value = false;
    })
    .catch((err: any) => {
      treeloading.value = false;
      VxeMessage('获取字典分类列表失败', VxeNotifyType.error);
    });
}
let pnameShow = ref(false); //父级分类显示
let showTypeDialog = ref(false); //最左侧字典根分类弹框

// 最左侧 新建字典根分类
function addRootDiagnosTypeDialog() {
  diagnosTypeForm.pid = 0;
  diagnosTypeForm.name = '';
  diagnosTypeForm.code = '';
  pnameShow.value = false;
  if (diagnosTypeList.length > 0) {
    // 根分类的顺序号
    const sx = diagnosTypeList[diagnosTypeList.length - 1].seq + 1;
    diagnosTypeForm.seq = sx;
  }
  showTypeDialog.value = true;
}

// 字典分类 新增or保存
function saveDiagnosType(formName: any) {
  const el: any = proxy.$refs[formName];
  el.validate((valid: any) => {
    if (!valid) {
      return false;
    }
    const obj = {
      id: diagnosTypeForm.id,
      pid: diagnosTypeForm.pid,
      name: diagnosTypeForm.name,
      code: diagnosTypeForm.code,
      seq: diagnosTypeForm.seq
    };
    let url = '';
    // 判断添加和编辑接口
    if (diagnosTypeForm.id) {
      url = '/lab/diagnosType/editDiagnosType';
    } else {
      url = '/lab/diagnosType/addDiagnosType';
    }
    proxy.$http
      .post(url, obj)
      .then((res: any) => {
        if (res.status.code === 1) {
          if (diagnosTypeForm.id) {
            VxeMessage('修改字典成功', VxeNotifyType.success);
          } else {
            VxeMessage('新增字典成功', VxeNotifyType.success);
          }
          findDiagnosTypeList();
          showTypeDialog.value = false;
          // 清空表单
          clearDiagnosTypeForm();
        } else {
          if (diagnosTypeForm.id) {
            VxeMessage('修改字典失败', VxeNotifyType.error);
          } else {
            VxeMessage('新增字典失败', VxeNotifyType.error);
          }
        }
      })
      .catch((err: any) => {
        VxeMessage('保存异常', VxeNotifyType.error);
      });
  });
}

// 新增字典分类小按钮
function appendDiagnosType(row: any) {
  diagnosTypeForm.pname = row.name;
  diagnosTypeForm.pid = row.id;
  diagnosTypeForm.name = '';
  diagnosTypeForm.code = '';
  diagnosTypeForm.seq = 1;
  if (row.children.length > 0) {
    const sx = row.children[row.children.length - 1].seq + 1;
    diagnosTypeForm.seq = sx;
  } else {
    diagnosTypeForm.seq = 1;
  }
  pnameShow.value = true;
  showTypeDialog.value = true;
}

// 编辑字典分类小按钮
function editDiagnosType(item: any, node: any) {
  diagnosTypeForm.pid = item.pid;
  diagnosTypeForm.id = item.id;
  diagnosTypeForm.name = item.name;
  diagnosTypeForm.code = item.code;
  diagnosTypeForm.seq = item.seq;
  diagnosTypeForm.pname = node.parent.data.name;
  if (item.pid == 0) {
    pnameShow.value = false;
  } else {
    pnameShow.value = true;
  }
  showTypeDialog.value = true;
}
function deletDiagnosType(row: any) {
  proxy
    .$confirm('确定删除此分类？', '提示', {
      cancelButtonClass: 'cancel-button',
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    })
    .then(() => {
      const url = '/lab/diagnosType/deletDiagnosType';
      if (row.id) {
        if (row.children.length === 0) {
          proxy.$http
            .post(url, row)
            .then((res: any) => {
              if (res.status.code === 1) {
                VxeMessage('删除成功', VxeNotifyType.success);
                findDiagnosTypeList();
              } else {
                VxeMessage('删除失败', VxeNotifyType.error);
              }
            })
            .catch((err: any) => {
              // VxeMessage('删除字典异常', VxeNotifyType.error);
            });
        } else {
          VxeMessage('该字典下存在子字典,不能删除', VxeNotifyType.error);
        }
      }
    });
}
// 字典分类弹框表单清空
function clearDiagnosTypeForm() {
  diagnosTypeForm.id = null;
  diagnosTypeForm.pid = null;
  diagnosTypeForm.pname = '';
  diagnosTypeForm.code = '';
  diagnosTypeForm.name = '';
  diagnosTypeForm.seq = 1;
}
// 判断字典分类弹框标题
function titleDiagnosType() {
  if (diagnosTypeForm.id) {
    return `编辑分类`;
  } else if (!diagnosTypeForm.id) {
    return `新建分类`;
  }
}
//点击左侧分类
function handleClickType(obj: any, node: any, data: any) {
  sltType = obj;
  findDiagnosTempList();
}
function getChildren(obj: any) {
  const children = obj.children;
  if (children.length > 0) {
    return getChildren(children[0]);
  } else {
    return obj;
  }
}

// 光标定位在指定字典分类上
function setCurTypeNode(nodeId: any) {
  proxy.$nextTick(() => {
    const treeName = 'dataTreeRef';
    const tree: any = proxy.$refs[treeName];
    tree.setCurrentKey(nodeId);
  });
}

function closeTypeDialog(formName: any) {
  const el: any = proxy.$refs[formName];
  //移除校验结果
  el.clearValidate();

  diagnosTypeForm.id = null;
  diagnosTypeForm.pid = null;
  diagnosTypeForm.pname = '';
  diagnosTypeForm.code = '';
  diagnosTypeForm.name = '';
  diagnosTypeForm.seq = 1;
  pnameShow.value = false;
  showTypeDialog.value = false;
}
// 回车查询
function keyupEnter(e: any) {
  if (e.$event.code == 'Enter') {
    findDiagnosTempList();
  }
}

function findDiagnosTempList() {
  tloading.value = true;
  diagnosTempList.length = 0; //放入数据前清空数据
  diagnosTempDescList.length = 0;
  const url = '/lab/diagnosTemp/findDiagnosTempList';
  proxy.$http
    //注意此处的数据条数
    .get(url, {
      params: {
        diagnosTypeId: sltType.id,
        searchValue: searchForm.searchValue
      }
    })
    .then((res: any) => {
      diagnosTempList.push(...res.data);
      const kn = diagnosTempList.find((k) => k.id == sltDiagnosTemp.value.id);
      if (isEmpty(kn)) {
        diagnosTempRowClick({ row: diagnosTempList[0] }); //默认选中第一条数据
      } else {
        diagnosTempRowClick({ row: kn }); //默认选中第一条数据
      }
      tloading.value = false;
    })
    .catch((err: any) => {
      tloading.value = false;
      // VxeMessage('获取获取当前字典的规则列表失败',VxeNotifyType.error)
    });
}

function findDiagnosTempDescList() {
  ploading.value = true;
  diagnosTempDescList.length = 0; //放入数据前清空数据
  const url = '/lab/diagnosTempDesc/findDiagnosTempDescList';
  proxy.$http
    //注意此处的数据条数
    .get(url, {
      params: {
        diagnosTempId: sltDiagnosTemp.value.id
      }
    })
    .then((res: any) => {
      diagnosTempDescList.push(...res.data);
      ploading.value = false;
    })
    .catch((err: any) => {
      ploading.value = false;
      // VxeMessage('获取获取当前字典的规则列表失败',VxeNotifyType.error)
    });
}

// 点击设计模式表格当前行触发右侧表单变化
function diagnosTempRowClick({ row }: any) {
  if (isEmpty(row)) {
    sltDiagnosTemp.value = {};
  } else {
    (proxy.$refs.tempTableRef as any).setCurrentRow(row);
    sltDiagnosTemp.value = row;
    findDiagnosTempDescList();
  }
}

function addDiagnosTempDialog() {
  diagnosTempForm.diagnosTypeId = sltType.id;
  diagnosTempForm.seq = diagnosTempList.length + 1;
  showDiagnosTempDialog.value = true;
}

function addDiagnosTempDescDialog() {
  diagnosTempDescForm.diagnosTempId = sltDiagnosTemp.value.id;
  diagnosTempDescForm.isEnable = 1;
  diagnosTempDescForm.seq = diagnosTempDescList.length + 1;
  showDiagnosTempDescDialog.value = true;
}

function saveDiagnosTemp(formName: any) {
  const el: any = proxy.$refs[formName];
  el.validate((valid: any) => {
    if (!valid) {
      return false;
    }
    const obj = {
      id: diagnosTempForm.id,
      tempCode: diagnosTempForm.tempCode,
      diagnosTypeId: diagnosTempForm.diagnosTypeId,
      tempName: diagnosTempForm.tempName,
      isEnable: diagnosTempForm.isEnable,
      seq: diagnosTempForm.seq
    };
    let url = '';
    // 判断添加和编辑接口
    if (diagnosTempForm.id) {
      url = '/lab/diagnosTemp/editDiagnosTemp';
    } else {
      url = '/lab/diagnosTemp/addDiagnosTemp';
    }
    proxy.$http
      .post(url, obj)
      .then((res: any) => {
        if (res.status.code === 1) {
          if (diagnosTempForm.id) {
            VxeMessage('修改成功', VxeNotifyType.success);
          } else {
            VxeMessage('新增成功', VxeNotifyType.success);
          }
          showDiagnosTempDialog.value = false;
          sltDiagnosTemp.value = res.data;
          findDiagnosTempList();
          // 清空表单
          clearDiagnosTempForm();
        } else {
          if (diagnosTempForm.id) {
            VxeMessage('修改失败', VxeNotifyType.error);
          } else {
            VxeMessage('新增失败', VxeNotifyType.error);
          }
        }
      })
      .catch((err: any) => {
        VxeMessage('保存异常', VxeNotifyType.error);
      });
  });
}

function saveDiagnosTempDesc(formName: any) {
  const el: any = proxy.$refs[formName];
  el.validate((valid: any) => {
    if (!valid) {
      return false;
    }
    const obj = {
      id: diagnosTempDescForm.id,
      diagnosTempId: diagnosTempDescForm.diagnosTempId,
      descCode: diagnosTempDescForm.descCode,
      descName: diagnosTempDescForm.descName,
      descText: diagnosTempDescForm.descText,
      isEnable: diagnosTempDescForm.isEnable,
      seq: diagnosTempDescForm.seq
    };
    let url = '';
    // 判断添加和编辑接口
    if (diagnosTempDescForm.id) {
      url = '/lab/diagnosTempDesc/editDiagnosTempDesc';
    } else {
      url = '/lab/diagnosTempDesc/addDiagnosTempDesc';
    }
    proxy.$http
      .post(url, obj)
      .then((res: any) => {
        if (res.status.code === 1) {
          if (diagnosTempDescForm.id) {
            VxeMessage('修改成功', VxeNotifyType.success);
          } else {
            VxeMessage('新增成功', VxeNotifyType.success);
          }
          showDiagnosTempDescDialog.value = false;
          findDiagnosTempDescList();
          // 清空表单
          clearDiagnosTempDescForm();
        } else {
          if (diagnosTempDescForm.id) {
            VxeMessage('修改失败', VxeNotifyType.error);
          } else {
            VxeMessage('新增失败', VxeNotifyType.error);
          }
        }
      })
      .catch((err: any) => {
        VxeMessage('保存异常', VxeNotifyType.error);
      });
  });
}

function deleteBatchDiagnosTemp() {
  const sltSuppliers = (proxy.$refs.tempTableRef as any).getCheckboxRecords();
  if (!(sltSuppliers.length > 0)) {
    VxeMessage('请勾选要删除的数据', VxeNotifyType.info);
  } else {
    proxy
      .$confirm('确定要删除当前勾选的数据？', '提示', {
        cancelButtonClass: 'cancel-button',
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
      .then(async () => {
        //后台删除数据
        const deldiagnosTempList = sltSuppliers.filter((p: any) => !isEmpty(p.id));
        if (deldiagnosTempList.length > 0) {
          const data = { diagnosTempList: deldiagnosTempList };
          const url = '/lab/diagnosTemp/batchDeleteDiagnosTemp';
          proxy.$http
            .post(url, data)
            .then((res: any) => {
              findDiagnosTempList(); // 获取检验仪器表格数据
              VxeMessage(res.status.msg, VxeNotifyType.success);
            })
            .catch((err: any) => {
              VxeMessage(err, VxeNotifyType.error);
            });
        }
      })
      .catch((err: any) => {
        // VxeMessage(err, VxeNotifyType.error);
      });
  }
}

function deleteBatchDiagnosTempDesc() {
  const sltSuppliers = (proxy.$refs.diagnosTempDescTableRef as any).getCheckboxRecords();
  if (!(sltSuppliers.length > 0)) {
    VxeMessage('请勾选要删除的数据', VxeNotifyType.info);
  } else {
    proxy
      .$confirm('确定要删除当前勾选的数据？', '提示', {
        cancelButtonClass: 'cancel-button',
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
      .then(async () => {
        //后台删除数据
        const delDiagnosTempDescList = sltSuppliers.filter((p: any) => !isEmpty(p.id));
        if (delDiagnosTempDescList.length > 0) {
          const data = { diagnosTempDescList: delDiagnosTempDescList };
          const url = '/lab/diagnosTempDesc/batchDeleteDiagnosTempDesc';
          proxy.$http
            .post(url, data)
            .then((res: any) => {
              findDiagnosTempDescList(); // 获取检验仪器表格数据
              VxeMessage(res.status.msg, VxeNotifyType.success);
            })
            .catch((err: any) => {
              VxeMessage(err, VxeNotifyType.error);
            });
        }
      })
      .catch((err: any) => {
        // VxeMessage(err, VxeNotifyType.error);
      });
  }
}

function closeDiagnosTempDialog(formMiddleName: any) {
  const el: any = proxy.$refs[formMiddleName];
  // 移除校验结果
  el.clearValidate();
  clearDiagnosTempForm();
  showDiagnosTempDialog.value = false;
}

function closeDiagnosTempDescDialog(formMiddleName: any) {
  const el: any = proxy.$refs[formMiddleName];
  // 移除校验结果
  el.clearValidate();
  clearDiagnosTempDescForm();
  showDiagnosTempDescDialog.value = false;
}

// 清空中间规则弹框表单
function clearDiagnosTempForm() {
  diagnosTempForm.id = null;
  diagnosTempForm.diagnosTypeId = null;
  diagnosTempForm.tempCode = '';
  diagnosTempForm.tempName = '';
  diagnosTempForm.isEnable = 1;
  diagnosTempForm.seq = 1;
}

function clearDiagnosTempDescForm() {
  diagnosTempDescForm.id = null;
  diagnosTempDescForm.diagnosTempId = '';
  diagnosTempDescForm.descCode = '';
  diagnosTempDescForm.descName = '';
  diagnosTempDescForm.descText = '';
  diagnosTempDescForm.isEnable = 1;
  diagnosTempDescForm.seq = 1;
}

// 编辑当前行规则
function editDiagnosTempDialog(row: any) {
  diagnosTempForm.id = row.id;
  diagnosTempForm.diagnosTypeId = row.diagnosTypeId;
  diagnosTempForm.tempCode = row.tempCode;
  diagnosTempForm.tempName = row.tempName;
  diagnosTempForm.isEnable = row.isEnable;
  diagnosTempForm.seq = row.seq;
  showDiagnosTempDialog.value = true;
}

function editDiagnosTempDescDialog(row: any) {
  diagnosTempDescForm.id = row.id;
  diagnosTempDescForm.diagnosTempId = row.diagnosTempId;
  diagnosTempDescForm.descCode = row.descCode;
  diagnosTempDescForm.descName = row.descName;
  diagnosTempDescForm.descText = row.descText;
  diagnosTempDescForm.isEnable = row.isEnable;
  diagnosTempDescForm.seq = row.seq;
  showDiagnosTempDescDialog.value = true;
}

// 判断中间弹框显示的标题
function titleDiagnosTemp() {
  if (diagnosTempForm.id) {
    return `编辑诊断`;
  } else {
    return `新建诊断`;
  }
}
function titleDiagnosTempDesc() {
  if (diagnosTempDescForm.id) {
    return `编辑诊断描述`;
  } else {
    return `新建诊断描述`;
  }
}
</script>

<style lang="scss" scoped>
#diagnosTempDiv {
  height: 100%;
  .bodyContent {
    height: calc(100% - 60px);
    .splitpanes {
      background-color: $base-white;
      // 附加按钮间距
      .button-blue,
      .button-red {
        margin: 5px 0 5px 5px;
      }
      .tableBody {
        height: calc(100% - 40px - 32px);
      }
      // 最左侧字典分类的树
      .sampleType {
        .tools-tree {
          min-width: 168px;
          padding: 0 5px 5px 5px;
          font-size: $font-size;
          border: none;
          .cirBtn {
            display: none;
            width: 16px;
            height: 16px;
            padding: 0px;
            margin-left: 10px;
          }
          .el-tree-node__content:hover {
            .cirBtn {
              display: inline-block !important;
            }
          }
        }
      }
      .el-tabs {
        height: 100%;
        :deep(.el-tabs__content) {
          height: calc(100% - 40px);
          padding: 0;
          .el-tab-pane {
            height: 100%;
          }
          #pane-first {
            padding: 15px;
          }
        }
      }
    }
  }
}
</style>

